#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>

void * self_intro(void *arg)
{
    sleep(1);
    int from_main = *((int *)arg);
    pthread_t self_pid = pthread_self();
    printf("I am thread(%ld)\n", self_pid);
    printf("I got %d from main.\n", from_main);

    pthread_exit((void *)"thread finished.\n");
}

int main(int argc, char *argv[])
{
    
    pthread_t tid;
    
    int num = 12312;

    int res = pthread_create(&tid, NULL, self_intro, &num);


    if (res != 0) {
        printf("thread_create: %s\n", strerror(res));
        return -1;
    }

    void *thread_res;
    pthread_join(tid, &thread_res);
    printf("thread create success(%lu)\n", tid);
    printf("from thread: %s\n", (char *)thread_res);


    return 0;
}
